<template>
	<view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #e60d64;">&#xe8ce;</text>专利号</view>
			<view class="input-content">
				<input class="text-input" type="text" placeholder="请输入专利号" v-model="number" />
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #6d16e6;">&#xe8ce;</text>国别</view>
			<view class="input-content">
				<picker @change="nationalityIndex=$event.detail.value" :value="nationalityIndex" :range="nationality">
					<text>{{nationality[nationalityIndex]}}</text>
				</picker>
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #e6c611;">&#xe8ce;</text>获得日期</view>
			<view class="input-content">
				<picker mode="date" :value="publishedTime" @change="publishedTime=$event.detail.value">
					<view class="uni-input">{{publishedTime}}</view>
				</picker>
			</view>
		</view>
		<view class="textarea">
			<textarea placeholder="请输入简介" v-model="con" />
			</view>
		
		<view class="bottom">
			<button type="primary" @click="submit"><text class="iconfont" style="color: #FFFFFF;">&#xe64a;</text>提交</button>
		</view>
	</view>
</template>
<script>
	import {patentEdit} from '@/api/tAchievementMaintenance.js'
	import {delPatentApply} from '@/api/tAchievementApply.js'
	import {getPatentInfo} from '@/api/tAchievementList.js'
	
	function getDate() {
		const date = new Date();
		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = date.getDate();
		month = month > 9 ? month : '0' + month;;
		day = day > 9 ? day : '0' + day;
		return `${year}-${month}-${day}`;
	}
	
	export default {
		data() {
			return {
				teaPatentId:'',
				tid: getApp().globalData.tid,
				name: '',
				number:'',
				con: '',
				publishedTime:getDate(),
				nationality:['中国','美国','加拿大','日本','英国','新加坡'],
				nationalityIndex:0,
				teaPatentChangeId:''
			}
		},
		methods: {
			submit(){
				let data = {
					tid:this.tid,
					teaPatentId:this.teaPatentId,
					name:this.name,
					number:this.number,
					nationality:this.nationality[this.nationalityIndex],
					publishedTime:this.publishedTime,
					con: this.con
				}
				patentEdit(data).then(res=>{
					// console.log(res)
					if(res.data.code==0){
						uni.showModal({
							content:'提交成功',
							showCancel:false,
							success:() =>{
								delPatentApply({
									teaPatentChangeId:this.teaPatentChangeId
								})
								uni.navigateBack()
							}
						})
					}else{
						uni.showModal({
							content:'提交失败',
							showCancel:false,
						})
					}
				}).catch(err=>{
					uni.showModal({
						content:'网络异常',
						showCancel:false,
					})
				})
			}

		},
		onLoad(option) {
			this.teaPatentId=option.teaPatentId
			this.teaPatentChangeId=option.teaPatentChangeId
			uni.showLoading()
			getPatentInfo({
				teaPatentId:option.teaPatentId
			}).then(res=>{
				// console.log(res)
				this.name = res.data.data.name
				this.number= res.data.data.number
				for(let i in this.nationality){
					if(this.nationality[i]==res.data.data.nationality){
						this.nationalityIndex=i
						break
					}
				}
				this.publishedTime= res.data.data.publishedTime
				this.con= res.data.data.con
				uni.hideLoading()
			})
		}
	}
</script>

<style>
	.iconfont {
		font-family: "iconfont" !important;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
		color: #C0C0C0;
		font-size: 16px;
		margin-right: 5px;
	}
	.input-item {
		height: auto;
		position: relative;
		height: 40px;
		margin: 5px 10px;
		border-bottom: 1px solid #C0C0C0;
		font-family: 'Courier New', Courier, monospace;
	}

	.input-item .title {
		position: absolute;
		top: 0;
		left: 0;
		width: 30%;
		height: 100%;
		/* text-align: center; */
		line-height: 40px;
		margin-left: 3px;
	}


	.input-item .input-content {
		position: absolute;
		top: 0;
		right: 0;
		width: 70%;
		height: 100%;
	}

	.input-item .input-content .text-input {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100%;
	}
	picker{
		margin-top: 5px;
	}
	
	.textarea{
		margin-top: 15px;
		padding: 0 10px;
		height: 150px;
	}
	.textarea textarea{
		width: 100%;
		border-radius: 10px;
		border: 1px solid #808080;
		font-family: 'Courier New', Courier, monospace;
	}
	.bottom{
		margin-top: 30px;
		padding: 0 10px;
	}
	
</style>
